package com.zls.controller;

import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.page.Result;
import com.zls.pojo.Item;
import com.zls.pojo.Taskplan;
import com.zls.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @GetMapping("findAll")
    public List<Item> findAll(){
        List<Item> all = itemService.findAll();
        return all;
    }

    /**
     * 列表查询
     */
    @PostMapping("all")
    public PageResult all(@RequestBody QueryPageBean queryPageBean){
        PageResult page = itemService.findPage(queryPageBean);
        return page;
    }
    /**
     * 列表添加
     */
    @PostMapping("add")
    public Result add(@RequestBody Item item){
        int i = itemService.addItem(item);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 查询修改列表
     */
    @GetMapping("findByIid")
    public Result findById(@RequestParam("iid") String iid){
        Item item=itemService.findByIid(iid);
        Result result=new Result();
        if (item!=null){
            result.setData(item);
            result.setFlag(true);
        }else {
            result.setMessage("系统错误");
        }
        return result;
    }
    /**
     * 修改
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Item item){
        int i = itemService.editItem(item);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
    /**
     * 删除
     */
    @GetMapping("delete")
    public Result delete(@RequestParam("iid")String iid){
        int i = itemService.deleteItem(iid);
        if (i>0){
            return Result.success();
        }else {
            return Result.fail();
        }
    }
}
